home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 0769A.ZIP / SUBSTRM.C < prev    next >
Text File  |  1987-11-11  |  4KB  |  96 lines

  1. /*********************************************************************/
  2. /**                                                                 **/
  3. /** SUBSTRMEMO ()                                                   **/
  4. /**                                                                 **/
  5. /** Syntax: SUBSTRMEMO (<expC) [, <expN> [, <expN]] )               **/
  6. /**                                                                 **/
  7. /** Returns: A string containing the specified number of lines from **/
  8. /**          a memo field.  The sub-portion of the memo field       **/
  9. /**          starts with the first number specified and includes    **/
  10. /**          all the lines up to and including the last number.     **/
  11. /**          Useful if you must print a memo field that is more     **/
  12. /**          than a page in length                                  **/
  13. /**          If start > end, a nul string is returned               **/
  14. /**                                                                 **/
  15. /** Example: ? substrmemo (memofld, 3, 5) => return lines 3 to 5 of **/
  16. /**                                          the field MEMOFLD      **/
  17. /**          ? substrmemo (memofld, 8)    => returns the remainder  **/
  18. /**                                          of the field MEMOFLD   **/
  19. /**                                          starting at line 8     **/
  20. /**          ? substrmemo (memofld, 7, 7) => return line 7          **/
  21. /**          ? substrmemo (memofld)       => returns whole field    **/
  22. /**          ? substrmemo (memofld, 5, 3) => return nul string      **/
  23. /**                                                                 **/
  24. /** Compiler:  Lattice v3.1 :: LC -ml -v -n substrm                 **/
  25. /**                                                                 **/
  26. /** Author:  Matt Colegrove                                         **/
  27. /**                                                                 **/
  28. /*********************************************************************/
  29.  
  30. #include <extend.h>
  31.  
  32. #define LF           '\n'
  33. #define SOFT_LF      ('\n' | 0x80)
  34. #define MAX_SIZE     0x7ff           /* 32K */
  35.  
  36. SUBSTRMEMO ()
  37.  
  38. {
  39.    unsigned char *_str_all();
  40.    unsigned char *str1, *pos1;         /* string and pointer to it */
  41.    unsigned char *str2, *pos2;
  42.    unsigned sizeof2;
  43.  
  44.    int lines, start, end;
  45.  
  46.    if (PCOUNT >= 1 && ISCHAR (1))
  47.       {
  48.       str1 = _parc (1);
  49.       pos1 = str1;
  50.       start = 1;
  51.       end   = MAX_SIZE;           /* guaranteed end of field */
  52.  
  53.       if (PCOUNT >= 2 && ISNUM (2))
  54.          {
  55.          start = _parni (2);
  56.  
  57.          if (PCOUNT == 3 && ISNUM (3))
  58.             {
  59.             end = _parni (3);
  60.             }
  61.          else
  62.             {
  63.             _retc ("ERROR: Too Many Parameters passed to SUBSTRMEMO");
  64.             }
  65.          }  /* endif PCOUNT >= 2 */
  66.  
  67.       lines = 1;      /* when we begin, we are on line 1 */
  68.       while (*pos1 && (lines < start))  /* spin pass lines before start */
  69.          {
  70.          if (*pos1 == LF || *pos1 == SOFT_LF)
  71.             lines++;
  72.          pos1++;
  73.          }
  74.  
  75.       sizeof2 = strlen (str1);
  76.       str2 = _str_all (sizeof2);  /* allocate space to str2 */
  77.       pos2 = str2;
  78.       while ((*pos1) && (*pos1 != 0x1a) && (lines <= end))
  79.          {
  80.          *pos2 = ((*pos1) & 0x7f);  /* strip of high order bit */
  81.          if (*pos1 == LF || *pos1 == SOFT_LF)
  82.             lines++;
  83.          pos1++;
  84.          pos2++;
  85.          }
  86.       *pos2 = '\0';   /* terminate the string */
  87.       _retc (str2);
  88.       _str_rel (str2, sizeof2);
  89.       }
  90.    else /* PCOUNT < 1 */
  91.       {
  92.       _retc ("ERROR: SUBSTRMEMO has no parameters passed to it");
  93.       }
  94. }
  95. /* end of substrm.c */
  96.